<!DOCTYPE html>
<html lang="en">
<head>
	<title>全一科技</title>
	<meta charset="UTF-8">
	<meta name="_token" content="{{ csrf_token() }}"/>
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<style>
		*{
			margin: 0;
			padding: 0;

		}
		.dv{
			margin:0 auto;
			margin-top:1rem;
			height: 60px;
			width: 80%;
			border:2px solid black;
			font-size: 20px;
			text-align: center;
			line-height: 60px;
			border-radius: 1rem;
			font-weight: bold;
		}

		.btn{
			width: 3rem;
			height: 3rem;
			border-radius: 50%;
			outline: none;
			margin-top: 5rem;
			margin-left: 2.2rem;
			font-size: 40px;
			text-align: center;
			line-height: 3rem;
			@if($res['status']==1)
background:red;
			@else
background:green;
			@endif
color: pink;
			font-weight: bold;
			border: none;
		}
		/* .btn.huise{
           background-color: #gray;
         }*/
		p{
			margin-left: 2.1rem;
			margin-top: -6rem;
			font-size: 0.8rem;
		}
	</style>
</head>
<body>
<input type="hidden" id="app" name="app" value="{{$apply}}">
<div class="dv">
	@if($res['status']==1) 当前是布防状态 @else 当前是撤防状态 @endif
</div>
<button  class="btn" id="dv1">@if($res['status']==1)关@else开@endif</button>
<p></p>
</body>
<script src="/admin/js/rem.js"></script>
<script src="/admin/js/jquery-1.8.3.min.js"></script>
<script>
    $(function(){
        $(".btn").click(
            function(){
                if($(".btn").text()=="开"){
                    $(this).css("background","red");
                    $(".btn").text("关");
                    $(".dv").text("当前是布防状态");
                    filterClick(this)

                }else{
                    $(this).css("background","green");
                    $(".btn").text("开");
                    $(".dv").text("当前是撤防状态");
                    filterClick(this)
                }
                if(!($(".btn")[0].disabled)){
                    $(".btn")[0].disabled = true;
                    $(".btn").addClass('huise');
                    jishi(3);
                }
            }
        )
    })
    function filterClick(me){
        var apply = $('input[name=app]').val();
        console.log(apply);
        var lg;
        if($(".btn").text()=="关") {
            lg = 1;
        }else{
            lg = 0;
        }
        $.ajax({
            type: "post",
            url: "/admin/binding/disarm",
            data: {"apply":apply,"status":lg},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            },
            dataType: "html",
            success: function (str) {

            }
        });
    }

    function jishi(a){
        var timmer=setInterval(()=>{
                if(a>0){
            $('p').html('正在生效&nbsp<span></span>');
            $('span').html(a);
            a--;
        }else{
            $('p').html('操作成功');
            $(".btn")[0].disabled = false;
            $(".btn").removeClass('huise');
            clearInterval(timmer);
        }
    }, 1000);
    }
</script>

</html>
